<template>
  <div class="dashboard-container">
    <div class="app-container">
      <div class="edit-form">
        <el-form ref="userForm" label-width="220px">
          <!-- 姓名 部门 -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="姓名" prop="username">
                <el-input size="mini" class="inputW" />
              </el-form-item>

            </el-col>

          </el-row>

          <!-- 工号 入职时间 -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="工号" prop="workNumber">
                <el-input size="mini" class="inputW" />
              </el-form-item>

            </el-col>

          </el-row>

          <!--手机 聘用形式  -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="手机" prop="mobile">
                <el-input
                  size="mini"
                  class="inputW"
                />
              </el-form-item>

            </el-col>

          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="部门" prop="departmentId">
                <!-- 放置及联部门组件 -->
              </el-form-item>

            </el-col>

          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="聘用形式" prop="formOfEmployment">
                <!-- <el-select size="mini" class="inputW" /> -->
              </el-form-item>

            </el-col>

          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="入职时间" prop="timeOfEntry">
                <el-date-picker
                  size="mini"
                  type="date"
                  value-format="yyyy-MM-dd"
                  class="inputW"
                />
              </el-form-item>

            </el-col>

          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="转正时间">
                <el-date-picker
                  size="mini"
                  type="date"
                  class="inputW"
                />
              </el-form-item>

            </el-col>

          </el-row>

          <!-- 员工照片 -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="员工头像">
                <!-- 放置上传图片 -->
                <!-- <ImageUpload :value="staffPhoto" @input="staffPhoto=$event" /> -->
                <ImageUpload v-model="staffPhoto" />
              </el-form-item>

            </el-col>

          </el-row>

          <!-- 保存个人信息 -->
          <el-row type="flex">
            <el-col :span="12" style="margin-left:220px">
              <el-button size="mini" type="primary" @click="save">保存更新</el-button>

            </el-col>

          </el-row>

        </el-form>

      </div>

    </div>

  </div>

</template>

<script>
import ImageUpload from './components/image-upload.vue'
import { getUserDetailById, updateUser } from '@/api/user'
export default {
  components: {
    ImageUpload
  },
  data() {
    return {
      staffPhoto: null
    }
  },
  created() {
    this.getUserDetail()
  },
  methods: {
    async getUserDetail() {
      const res = await getUserDetailById(this.$route.params.id) // 接收父级传过来的id ,知道我点的是哪个id进入的页面,   传给后端拿数据
      this.staffPhoto = res.staffPhoto // 员工头像 ,如果有就用后端的,没有就没有
    },
    async save() {
      await updateUser({
        id: this.$route.params.id,
        staffPhoto: this.staffPhoto,
        mobile: '13244556546', // 手机号是账号不允许改  用本身的手机号传入即可
        // 以下数据写死 用于课堂测试
        username: '张三三',
        timeOfEntry: '2020-01-01',
        workNumber: '00001',
        correctionTime: '2020-01-01',
        departmentId: 4,
        formOfEmployment: 2
      })
      this.$message.success('更新成功')
    }
  }

}
</script>

<style scoped lang="scss">
    .edit-form {
      background: #fff;
      padding: 20px;
      .inputW {
        width: 380px
      }
    }

</style>
